#!/bin/bash

# 检查Python3是否已安装
if ! command -v python3 &>/dev/null; then
    echo "Python3 is not installed. Installing Python3..."
    # 这里根据您的操作系统选择合适的命令来安装Python3（假设是基于Debian/Ubuntu的系统）
    sudo apt update && sudo apt install -y python3
fi

# 确认Python3版本
python3 --version

# 安装pip3，如果尚未安装
if ! command -v pip3 &>/dev/null; then
    echo "Installing pip3 for Python3..."
    # Debian/Ubuntu系列系统的pip3安装
    sudo apt install -y python3-pip
fi

# 安装所需Python库
sudo pip3 install requests
sudo apt install -y python3-bs4
sudo apt install -y python3-openpyxl
sudo python3 -m pip install html5lib

echo "All installations completed successfully."

# 可选：检查安装的库版本以确认安装是否成功
# python3 -c "import requests; print(requests.__version__)"
# python3 -c "from bs4 import BeautifulSoup; print(BeautifulSoup.__version__)"
# python3 -c "import openpyxl; print(openpyxl.__version__)"

exit 0